package com.heiye.quiz.biz.consumer;

import com.heiye.quiz.biz.constant.MQConstants;
import com.heiye.quiz.biz.service.QuizService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * @author: heiye
 * @date: 2025/03/19 下午8:47
 * @version: v1.0.0
 * @description: 删除本地问题缓存
 */
@Slf4j
@Component
@RocketMQMessageListener(
        // Group
        consumerGroup = "interact_group_" + MQConstants.TOPIC_DELETE_QUIZ_LOCAL_CACHE,
        // 消费的主题 Topic
        topic = MQConstants.TOPIC_DELETE_QUIZ_LOCAL_CACHE,
        // 广播模式
        messageModel = MessageModel.BROADCASTING
)
public class DeleteQuizLocalCacheConsumer implements RocketMQListener<String> {

    @Resource
    private QuizService quizService;

    @Override
    public void onMessage(String body) {
        Long quizId = Long.valueOf(body);
        log.info("## 消费者消费成功, quizId: {}", quizId);

        quizService.deleteQuizLocalCache(quizId);
    }
}
